﻿// -------------------------------------------------------------------------------------------------------------------------------
// <copyright file="DenseVector{T}.cs" company="Exul">
//     Copyright (c) Exul. All rights reserved.
// </copyright>
// <author>
//     Exul
// </author>
// -------------------------------------------------------------------------------------------------------------------------------

namespace ExulLibrary.Mathematics.LinearAlgebra
{
    #region Usings

    using System;

    using ExulLibrary.Exceptions;

    #endregion

    /// <summary>
    ///     Represents a dense vector.
    /// </summary>
    /// <typeparam name="T">
    ///     The type of values of vector elements.
    /// </typeparam>
    public sealed class DenseVector<T>
    {
        #region Constructors and Destructors

        #region public

        /// <summary>
        ///     Initializes a new instance of the <see cref="DenseVector{T}"/> class.
        /// </summary>
        /// <param name="length">
        ///     The length of the new <see cref="DenseVector{T}"/>.
        /// </param>
        /// <exception cref="NegativeOrZeroSizeException">
        ///     <paramref name="length"/> is negative or equal to zero.
        /// </exception>
        public DenseVector(int length)
        {
            #if SAFE

            if (length <= 0)
            {
                throw new NegativeOrZeroSizeException("length", length);
            }

            #endif

            this.Length = length;
            this.Values = new T[length];
        }

        /// <summary>
        ///     Initializes a new instance of the <see cref="DenseVector{T}"/> class.
        /// </summary>
        /// <param name="data">
        ///     The collection of values of vector elements.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="data"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="EmptyCollectionException">
        ///     <paramref name="data"/> is empty.
        /// </exception>
        public DenseVector(T[] data)
        {
            #if SAFE

            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            if (data.Length == 0)
            {
                throw new EmptyCollectionException("data");
            }

            #endif

            this.Length = data.Length;
            this.Values = data;
        }

        #endregion

        #endregion

        #region Properties

        #region public

        /// <summary>
        ///     Gets the number of elements in the vector.
        /// </summary>
        /// <value>
        ///     The number of elements in the vector.
        /// </value>
        public int Length
        {
            get;
            private set;
        }

        /// <summary>
        ///     Gets the collection of values of vector elements.
        /// </summary>
        /// <value>
        ///     The collection of values of vector elements.
        /// </value>
        public T[] Values
        {
            get;
            private set;
        }

        #endregion

        #endregion
    }
}